<?php

$title = '商品热销排行';
include "header.php";

?>
<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space8">
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-header">热门商品统计(可以帮助您找到热门商品)</div>
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-brief layadmin-latestData">
                        <ul class="layui-tab-title">
                            <li onclick="HotCommodity.ToHotAll()" class="layui-this">商品销售总榜</li>
                            <li onclick="HotCommodity.ToDayHot()">今日热卖</li>
                            <li onclick="HotCommodity.HotYesterday()">昨日热卖</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show"><table id="ToHotAll" lay-filter="ToHotAll"></table></div>
                            <div class="layui-tab-item"><table id="ToDayHot" lay-filter="ToDayHot"></table></div>
                            <div class="layui-tab-item"><table id="HotYesterday" lay-filter="HotYesterday"></table></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    .layui-table-fixed{
        z-index: -1;
    }
</style>
<?php include "bottom.php"; ?>
<script>
    var HotCommodity = {
        ToHotAll: function() {
            layui.use('table', function() {
                var table = layui.table;
                //热卖商品统计总榜
                table.render({
                    elem: '#ToHotAll',
                    url: './ajax.php?act=ToHot&type=All', //数据接口
                    page: true, //开启分页
                    cols: [
                        [
                            //表头
                            { field: 'gid', title: 'GID', width: 70, sort: true, fixed: 'left' },
                            { field: 'name', templet: '#name', title: '商品名称', width: 200 },
                            { field: 'count', templet: '#count', title: '售出数量', width: 120, sort: true },
                            { field: 'money', templet: '#money', title: '销售总额', width: 200 },
                            { field: 'cost', templet: '#cost', title: '订单成本' , width: 200}
                        ]
                    ]
                });
            });
        },
        ToDayHot: function() {
            layui.use('table', function() {
                var table = layui.table;
                //今日热卖商品统计
                table.render({
                    elem: '#ToDayHot',
                    url: './ajax.php?act=ToHot&type=Day', //数据接口
                    page: true, //开启分页
                    cols: [
                        [
                            //表头
                            { field: 'gid', title: 'GID', width: 70, sort: true, fixed: 'left' },
                            { field: 'name', templet: '#name', title: '商品名称', width: 200 },
                            { field: 'count', templet: '#count', title: '售出数量', width: 120, sort: true },
                            { field: 'money', templet: '#money', title: '销售总额', width: 200 },
                            { field: 'cost', templet: '#cost', title: '订单成本' , width: 200}
                        ]
                    ]
                });
            });
        },
        HotYesterday: function() {
            layui.use('table', function() {
                var table = layui.table;
                //今日热卖商品统计
                table.render({
                    elem: '#HotYesterday',
                    url: './ajax.php?act=ToHot&type=Yesterday', //数据接口
                    page: true, //开启分页
                    cols: [
                        [
                            //表头
                            { field: 'gid', title: 'GID', width: 70, sort: true, fixed: 'left' },
                            { field: 'name', templet: '#name', title: '商品名称', width: 200 },
                            { field: 'count', templet: '#count', title: '售出数量', width: 120, sort: true },
                            { field: 'money', templet: '#money', title: '销售总额', width: 200 },
                            { field: 'cost', templet: '#cost', title: '订单成本' , width: 200}
                        ]
                    ]
                });
            });
        }
    };

    HotCommodity.ToHotAll();
</script>
<script type="text/html" id="name">
    <a lay-href="http://baidu.com/" lay-text="商品{{ d.name }}的订单" style="color: #0000ff"
       lay-tips="商品{{ d.name }}共售出了{{ d.count }}件，其中消耗用户余额{{ d.money }}元，耗费成本{{ d.cost }}元！<hr>点击查看商品下的订单列表！">{{ d.name
        }}</a>
</script>
<script type="text/html" id="count">
    <font color="#20b2aa">{{ d.count }}个</font>
</script>
<script type="text/html" id="money">
    <font color="#2e8b57">{{# return (d.money==null?'0.00':d.money) }}元</font>
</script>
<script type="text/html" id="cost">
    <font color="#ff0000">{{ (d.cost==null?'0.00':d.cost) }}元</font>
</script>
